/*
 * @Author: mark
 * @Date: 2023-06-24 21:13:07
 * @LastEditors: mark
 * @LastEditTime: 2024-02-16 19:53:46
 * @FilePath: /自研/RuoYi_egg/ruoyi-egg/config/config.default.js
 * @Description:
 *
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved.
 */
/* eslint valid-jsdoc: "off" */

"use strict";
const path = require("path");
/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = (appInfo) => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = (exports = {});

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + "_1687612361827_2349";

  // add your middleware config here
  config.middleware = ["checkToken", "logger", "consoleToFile"];

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  //sequelize config
  config.sequelize = {
    dialect: "mysql", // support: mysql, mariadb, postgres, mssql
    database: "ruoyi_egg", //数据库名
    host: "127.0.0.1",
    port: "3306",
    username: "root", //账号
    password: "123mysql", //密码
    timezone: "+08:00", // 保存为本地时区,mysql保存时会自动保存为UTC格式
    // sequelize 配置
    define: {
      // 添加createAt,updateAt,deleteAt时间戳
      timestamps: true,
      createdAt: "create_time",
      // 将updatedAt对应到数据库的updated_at字段
      updatedAt: "update_time",
      // 使用软删除，即仅更新 deleteAt 时间戳 而不删除数据 false表示硬删除
      paranoid: false,
      // 不允许修改表名
      freezeTableName: true,
      // 禁止驼峰式字段默认转为下划线
      underscored: false,
    },
    // 打印日志
    logging: false,
    // 时间格式化
    dialectOptions: {
      dateStrings: true,
      typeCast: true,
    },
  };

  //jwt
  config.jwt = {
    secret: "ruoyi-egg$#%#%^&&&@#$!@#!#&***$#$%@#202306251236125351253",
    sign: {
      //jwt.sign(***,***,[options,***])方法中，options的默认设置可以在这里配置；
      // 过期时间24小时
      expiresIn: 24 * (60 * 60), //多少s后过期。actionToken.js中,jwt.sing(plyload,secret,{expiresIn:number})会被合并，调用时设置优先级更高;
    },
  };

  //csrf
  config.security = {
    csrf: {
      enable: false,
    },
    // 跨域白名单
    domainWhiteList: ["http://localhost:1024"],
  };

  //跨域配置
  config.cors = {
    origin: "*",
  };
  //日志
  config.logger = {
    level: "DEBUG",
    consoleLevel: "DEBUG",
    //日志位置
    dir: path.join(appInfo.root, "logs"),
    appLogName: `${appInfo.name}-web.log`,
    coreLogName: `${appInfo.name}-egg-web.log`,
    agentLogName: `${appInfo.name}-egg-agent.log`,
    errorLogName: `${appInfo.name}-common-error.log`,
  };
  /**
   * 配置swagger
   * @property {String} dirScanner - 插件扫描的文档路径
   * @property {String} basePath - api前置路由
   * @property {Object} apiInfo - 可参考Swagger文档中的Info
   * @property {Array[String]} apiInfo - 可参考Swagger文档中的Info
   * @property {Array[String]} schemes - 访问地址协议http或者https
   * @property {Array[String]} consumes - contentType的集合
   * @property {Array[String]} produces - contentType的集合
   * @property {Object} securityDefinitions - 安全验证，具体参考swagger官方文档
   * @property {Boolean} enableSecurity - 是否使用安全验证
   * @property {Boolean} routeMap - 是否自动生成route
   * @property {Boolean} enable - swagger-ui是否可以访问
   */
  config.swaggerdoc = {
    dirScanner: "./app/controller",
    apiInfo: {
      title: "API",
      description: "Swagger API for Project",
      version: "1.0.0",
    },
    schemes: ["http", "https"],
    consumes: ["application/json"],
    produces: ["application/json"],
    enableSecurity: false,
    // enableValidate: true, // 如果需要数据校验，可以开启此项
    routerMap: true,
    enable: true,
  };

  //redis配置
  config.redis = {
    clients: {
      client0: {
        port: 6379,
        host: "127.0.0.1",
        password: null,
        db: 0,
      },
      client1: {
        port: 6379,
        host: "127.0.0.1",
        password: null,
        db: 1,
      },
    },
  };

  //启动参数
  config.cluster = {
    listen: {
      port: 10020,
      hostname: "0.0.0.0",
    },
  };

  config.basicUrl = "/dev-api";
  return {
    ...config,
    ...userConfig,
  };
};
